<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" import="com.tjtt.common.utils.DateUtilsAll"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>
  <head>
  <base target="_self"/>
  
  <title>表单基本信息添加页面</title>
  	<meta http-equiv="X-UA-Compatible" content="IE=7" />
  	<%@ include file="../jslib/jquerylib.jsp" %>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	<style type="text/css">
   		html{
		    overflow-x: hidden;
		}  		
   </style>
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    $().ready(function() {
	$("#pageFrom").validate({
		onkeyup :false,onclick:false,
			rules: {
				fromName: {
				      required: true,
				      withoutspecial: true,
				      maxlength:40
				},
				fromColumn:{
					required:true,
					number:true
				}
			},
		messages: {
			fromName: {
			      required: "表单名称不能为空",
			      maxlength: "内容过长",
			      withoutspecial : "字符违规"
			},	
			fromColumn:{
				required:"表单列数不能为空",
				number:"表单列数只能为数字"
			}
		},  
	   /* 重写错误显示消息方法,以alert方式弹出错误消息 */  
	   showErrors : function(errorMap, errorList) {
		    var msg = "";  
		    $.each(errorList, function(i, v) {  
		     msg = (v.message + "\r\n");  
		    
		    if (msg != ""){  
		     alert(msg);
		     return false;  
		     }
		     });  
		   onfocusout=false; 
	   } 
	  });  
			
				
    	// 准备好Options对象
    	var options = {
    	    url:'<%=request.getContextPath() %>/auto!saveForm.action',
    	     beforeSubmit: function() {
    	        if('${formid}'==3923 || '${formid}'==4521){
    	           var samplename = $.trim($("#T_SAMPLENAME").val());   //样品名称
    	           var pici = $.trim($("#T_PICI").val());                //批次
    	           var shenchans = $.trim($("#T_MANUFACTURER").val());  //生产商
    	           
    	           var valueMsg1 = "";
    	           if(samplename!=''){
    	              valueMsg1 = "T_SAMPLENAME='"+samplename+"'";
    	           }
    	           if(pici!=''){
    	             valueMsg1 = valueMsg1+" AND T_PICI='"+pici+"'";
    	           }
    	           if(shenchans!=''){
    	             valueMsg1 = valueMsg1+" AND T_MANUFACTURER='"+shenchans+"'";
    	           }
    	           if(valueMsg1!=''){
    	               valueMsg1 = valueMsg1 +" AND ID <>"+$("#ID").val();
    	               var flag1 = checkMessageWeiyi('GWM_SAMPLE','T_SAMPLENAME',valueMsg1);
    	               if(flag1){
	    	              alert("样品已存在,请重新输入");
	    	              $("#T_SAMPLENAME").focus();
	    	              return false;
	    	           }
    	           }
    	           
    	        }
    	        //检测单位管理  校验检测单位是否唯一
    	        if('${formid}'==3921){
    	          var valueMsg = "T_JIANCEDANWEI='"+$.trim($("#T_JIANCEDANWEI").val())+"' AND ID <>"+$("#ID").val();
    	          var flag = checkMessageWeiyi('GWM_JIANCEDANWEI','T_JIANCEDANWEI',valueMsg);
    	          if(flag){
    	              alert("检测单位已存在,请重新输入");
    	              $("#T_JIANCEDANWEI").focus();
    	              return false;
    	          }
    	        }
    			return $('#pageFrom').form('enableValidation').form('validate');
    		},
    	    dataType:'json',
    	    success: function(data) {
    	      if(data.result=='success'){
				alert("添加成功");
				
				if('${sign}'=='0'){
				}else{
				   api.close();
				}
				 W.gridSearch();
    	      }else if(data.result=='exist'){
    	      		alert("结构区别号已存在，请重新输入");
    	      }else{
    	      	alert("系统繁忙，请您稍后再试！");
    	      	api.close();
				W.gridSearch();
    	      }
    	}};
    	
		$('#saveBtn').click(function(){
		    
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		$('#saveBtn1').click(function(){
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		
		$('#closeBtn').click(function(){
			api.close();
		});
		if('${formid}'==3923){  //常规流程中 添加样品
	       $("#columns").val($("#columns").val()+'T_TASKID,');
	    }
	    if('${formid}'==4521){  //整车流程中 添加样品
	       $("#columns").val($("#columns").val()+'T_TASKID,');
	    }
	    if('${formid}'==4424){  //整车可靠性检测流程 添加故障信息
	       $("#columns").val($("#columns").val()+'TASKID,ADDTIME,ADDUSER,XITONGNAME,LINGBUJIANNAME,GUZHANGPATTERNNAME,CHXINGNAME,');
	    }
	});
 	//选择序号生成规则
   function chooseCustomNo(fieldname){
		var datas = window.showModalDialog("<%=basePath%>/auto/choose_custom_no_list.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById(fieldname).value = json1.customNum;
			 $('#TEST_ID').val(json1.customId);
			 
		}
   }
	function countlen(textarea){
	    if (textarea.value.length> 250){
	        alert("最多为250个字符,字符输入超出限制!");
	        textarea.value=textarea.value.substring(0,250);
	    }
	    return true;
	}
	
	function selectformtype(){
		var k = window.showModalDialog('autoFromsAction!getDicselectviewinfo.action?id=321',null,"dialogWidth=850px;dialogHeight=430px;resizable=yes");
		if (k==undefined)
		{
			k = '';
		}
		document.getElementById("suoslx").value = k;
	}
	//选择人员
	function selectperson(id)
	{
		if('${formid}'==3521&&id=='T_ZERENREN'){   //试验计划申请选择责任人
		    var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/selectUserByRole.jsp?roleid=350", window, "dialogWidth:500px;status:no;dialogHeight:500px");
		    document.getElementById("user_"+id).value = users.username;
            document.getElementById(id).value = users.userid;
		}else{
		 var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp", window, "dialogWidth:930px;status:no;dialogHeight:500px");
   	 	 if (users != null) {
   		    var userIds = [];
            var userNames = [];
            for(var i=0;i<users.length;i++){
               userIds.push(users[i]['userid']);
               userNames.push(users[i]['username']);
            }
            document.getElementById("user_"+id).value = userNames.join();
            document.getElementById(id).value = userIds.join();
    	  }
    	}
    
	}
	//选择部门
	function selectdept(id)
	{
		var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
	//选择外键数据信息
	//参数信息：表明，关联列，显示列
	function selectData(id,tablename,colname,disname,cnname,fieldslist,formid){	
		var media="";
	    if(tablename=='PTEM_TYPE_PRESSURELEVEL')
	    {
	    	media=$("#MEDIA").val();
	    	//alert(media);
	    }
	    var fileColname ='hideFileName';
	    if(tablename=='DIC_STANDARD'){
	      fileColname = "YCLJS_GYYW";
	    }
		/*if(tablename=="SYS_ORGANIZATION")
		{
			disname+=",UNIT_APTITUDE,UNIT_LEVEL,UNIT_ADDR,UNIT_POSTCODE,UNIT_STANDARD";
		}*/
		var orgid=document.getElementById("orgid").value;	
	    //var url="<%=basePath%>/form/auto_choose_list.jsp?flag=0&tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&id="+id+"&fileColname="+fileColname+"&temp="+Math.round(Math.random()*10000);
	    var url="<%=basePath%>/auto!chooseDatalist.action?byTableValueId=<%=request.getAttribute("byTableValueId")%>&tablename="+tablename+"&unittype="+cnname+"&colname="+colname+"&orgid="+orgid+"&disname="+disname+"&id="+id+"&media="+media+"&cnname="+escape(encodeURIComponent(cnname))+"&fileColname="+fileColname+"&formid="+formid+"&fileName="+id+"&temp="+Math.round(Math.random()*10000);
	    var height = 500;
		var width = 500;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);
	   
	    /*var   datas = window.showModalDialog("<%=basePath%>/auto!chooseDatalist.action?byTableValueId=<%=request.getAttribute("byTableValueId")%>&tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&fileColname="+fileColname+"&formid="+formid+"&fileName="+id+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=800px;dialogHeight=500px");
	       if(typeof(datas) == 'undefined'){
		   }else{
			 var json1 = eval('(' + datas + ')');
			 document.getElementById(id).value = json1.ID;
			
			 var disnamearray = disname.split(',');
			 //检测项目管理  添加页面选择检测单位
			 if(formid=='3942'&&id=='T_JIANCEDANWEI'){
			     $("#data_T_JIANCEDANWEI").val(json1.T_JIANCEDANWEI);  
			     $("#T_GONGSIDAIMA").val(json1.T_GONGSIDAIMA);
			      $("#T_JIANCEDIDIAN").val(json1.T_JIANCEDIDIAN);
			 }else if(formid=='4424'){//整车可靠性试验流程  添加故障页面
			 	if(id=='CHEXING'){//车型
			 		document.getElementById("CHXINGNAME").value = json1[disnamearray[0]];
			 		document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	}else if(id=='ZIXITONG'){//子系统
			 		document.getElementById("XITONGNAME").value = json1[disnamearray[0]];
			 		document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	}else if(id=='LINGBUJIAN'){//零部件
			 		document.getElementById("LINGBUJIANNAME").value = json1[disnamearray[0]];
			 		document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	}else if(id=='GUZHANGPATTERN'){//故障模式
			 		document.getElementById("GUZHANGPATTERNNAME").value = json1[disnamearray[0]];
			 		document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	}
			 }else if(formid=='4421'){//添加总成
			     document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	 document.getElementById("BUWEINAME").value = json1[disnamearray[0]];
			 	 $("#columns").val($("#columns").val()+'BUWEINAME,');
			 }else if(formid=='4422'){//添加零部件
			 	 document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 	 document.getElementById("BUWEI").value = json1[disnamearray[1]];
			 	 
			 }else{
			    document.getElementById("data_"+id).value = json1.NAME;
			   if (fieldslist!=undefined){
			 	var fieldslistarray = fieldslist.split(',');
			 	for(var i=0;i<fieldslistarray.length;i++){
			 		if (i==0){
			 			document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 		}
			 		if(fieldslistarray[i] == "COUNT"){
			 			$('#COUNT').numberbox('setValue', json1[disnamearray[i]]);
			 		}else{
			 			document.getElementById(fieldslistarray[i]).value = json1[disnamearray[i]];
			 		}
			 	}
			   }
			   else{
			 	document.getElementById("data_"+id).value = json1[disnamearray[0]];
			   }
			}			 
		  }
		  */
	}
	//判断是否唯一
	function checkMessageWeiyi(tableName,columName,valueMsg){
	  var flag = false;
	  var  params = {
	               "tableName":tableName,
	               "flowtaskid":'${flowtaskid}',
	               "columName":columName,
	               "valueMsg":encodeURIComponent(valueMsg)
	              };
	  $.ajax({
			type: "POST",
			url :'<%=request.getContextPath() %>/auto!checkMessageWeiyi.action',  
			dataType: "json",
			data:params,
			async: false,//取消异步提交
			success : function(data, textStatus) {  
				if(data.result=='true'){
				   flag = true;
				}
				else if(data.result=='error'){
				   alert("校验唯一性失败!");
				   return false;
				}
			},
			error:function(){}
		});
		return flag;
	}
</script>
 <style type="text/css">
	body{
		background:#ffffff; background-image:url(images/);
	}
	.tab_input{border: 1px solid #999;padding: 5px;width: 250px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
</style>
</head>
<body>
  	<form action="<%=request.getContextPath() %>/auto!saveForm.action" id="pageFrom" name="pageFrom" class="easyui-form" data-options="novalidate:true" method="post">
  		<input type="hidden" id="formid" name="formid" value="${requestScope.formnew.id }"/>
  		<input type="hidden" id="columns" name="columns" value="${requestScope.columns }"/>
  		<input type="hidden" id="BUWEINAME" name="BUWEINAME" value=""/>
  		<input type="hidden" id="orgid" name="orgid" value=""/>
  		<table width="100%" border="0" align="center" >
  			${requestScope.tableContent }
		</table>
		<table width="100%" border="0" align="center" class="formTableNew">
			<td align="center">
		    	<% if("0".equals(request.getParameter("sign"))){ %>
		    	  <!-- 常规检测流程添加样品 -->
		    	  <input id="saveBtn" type="button" value="保 存" class="form_bt_orange" />
		    	<%}else{ %>
		    	<input id="saveBtn" type="button" value="提 交" class="form_bt_orange" />
		        <%} %>
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		   
		</table>
		 <br><br>
	</form>
  </body>
</html>
